<?php 
namespace app\admin\controller;

use think\Controller;
use think\Request;
use think\Db;
use think\Session;

class Login extends Controller
{
    public function __construct(Request $request = null)
    {
        
         $row = Db::table('hc_uj')
            ->alias('ur')
           
            ->join('hc_juese r', 'ur.uid = r.uid')
            ->join('hc_jj rr','r.uid=rr.uid')
            ->join('hc_jiedian f','rr.cid=f.cid')
            ->where('ur.id','=',Session::get('id','think'))
            ->select();
            // var_dump(Session::get('id','think'));die;
            // dump($row);die;
            // 
            $fun = [];
            foreach ($row as $k => $v) {
                array_push($fun,$k=array($v['cont']=>$v['func']));
            }
            // dump($fun);die;

            //存入session
            foreach ($fun as $a => $b){
                 foreach ($b as $c => $d){
                    Session::set($d,$c,$c);
                }
            }

            //增加默认权限
            Session::set('index','index','index');
            Session::set('logindo','index','index');
            Session::set('logout','index','index');

            //增加默认查看后台工作人员列表的权限
            Session::set('admin','con2','index');

            

            //判断权限
           // var_dump($_SESSION);

            //当前所在模块
            $con = strtolower($request->controller());
            $func = $request->action();
            // dump($func);
            // dump($con);
            // dump(Session::has($func,$con));die;




            if ((Session::has($func,$con)) === false){
                return $this->error('你的权限不够',url('/admin'));
                
            }
    }
}











